[org 0x1000]

dw 0x55aa;魔数 用于教研

mov si, loading
call print

xchg bx, bx

detect_momery:
    xor ebx, ebx

    ;es:di 结构体的缓存位置
    mov ax, 0
    mov es, ax

    mov edi, ards_buffer

    mov edx, 0x534d4150 ;固定签名

.next:
    mov eax, 0xe820
    mov ecx, 20
    int 0x15

    jc error ; JC：JumpifCarry（有进bai位、即CF＝1，则跳转）,检查CF，是否发生错误

    add di, cx 

    inc word [ards_count]

    cmp ebx, 0
    jnz .next
    mov si,detecting
    call print

    xchg bx, bx

    ;结构体位置
    mov ecx, [ards_count]
    ;结构体指针
    mov si, 0
.show:
    mov eax,[ards_buffer + si]
    mov ebx, [ards_buffer + si + 8]
    mov edx, [ards_buffer + si + 16]
    add si, 20

    xchg bx, bx

    loop .show

jmp $

print:
    mov ah,0x0e
.next:
    mov al,[si]
    cmp al,0
    jz .done
    int 0x10
    inc si
    jmp .next
.done:
    ret

loading:
    db "loading Onix...",10,13,0 ;\n \r end

detecting:
    db "Detecting Memory Success...",10,13,0 ;\n \r end

error:
    mov si, .msg
    call print
    hlt
    jmp $
    .msg db "Loding error...",10,13,0 ;\n \r end

ards_count:
    dw 0
ards_buffer: